<div>
    <form id="cases-form" method="post">
        <div class="form-group">
            <label>
                Judge Cases<br>
                <small class="form-text text-muted">Used for judging submissions</small>
            </label>
            <input class="form-control-file" type="file" name="file" multiple="multiple">
            <sub>judge cases should end with ".in" and ".out"</sub>
        </div>
        <div class="form-group">
            <button class="btn btn-success" id="upload-cases">Upload</button>
            <button type="button" class="btn btn-warning" id="reset-cases" onclick="reset()">Delete All</button>
        </div>
    </form>
</div>

<form method="POST">
    <div class="form-group">
        <label>
            Name<br>
            <small class="form-text text-muted">Challenge Name</small>
        </label>
        <input type="text" class="form-control chal-name" name="name" value="{{ challenge.name }}">
    </div>

    <div class="form-group">
        <label>
            Category<br>
            <small class="form-text text-muted">Challenge Category</small>
        </label>
        <input type="text" class="form-control chal-category" name="category" value="{{ challenge.category }}">
    </div>

    <div class="form-group">
        <label>
            Message<br>
            <small class="form-text text-muted">
                Use this to give a brief introduction to your challenge.
            </small>
        </label>
        <textarea id="desc-editor" class="form-control chal-desc-editor" name="description"
                  rows="10">{{ challenge.description }}</textarea>
    </div>
    {% for i in [
        ['CPU Time Limit', 'Time Limit Exceeded', 'max_cpu_time', challenge.max_cpu_time],
        ['Execution Time Limit', 'KILL after this time', 'max_real_time', challenge.max_real_time],
        ['Memory Limit', 'Default: 32*1024*1024 bytes', 'max_memory', challenge.max_memory],
        ['Stack Limit', 'Default: 32*1024*1024 bytes', 'max_stack', challenge.max_stack],
        ['Process Limits', 'fork', 'max_process_number', challenge.max_process_number],
        ['Maximum Output Size', 'signal 25', 'max_output_size', challenge.max_output_size]
    ] %}
        <div class="form-group">
            <label>
                {{ i[0] }}<br>
                <small class="form-text text-muted">{{ i[1] }}</small>
            </label>

            <input type="number" class="form-control chal-attempts" name="{{ i[2] }}"
                   value="{{ i[3] }}">
        </div>
    {% endfor %}

    <div class="form-group">
        <label for="value">Current Value<br>
            <small class="form-text text-muted">
                This is how many points the challenge is worth right now.
            </small>
        </label>
        <input type="number" class="form-control chal-value" name="value" value="{{ challenge.value }}" disabled>
    </div>

    <div class="form-group">
        <label for="value">Initial Value<br>
            <small class="form-text text-muted">
                This is how many points the challenge was worth initially.
            </small>
        </label>
        <input type="number" class="form-control chal-initial" name="initial" value="{{ challenge.initial }}" required>
    </div>

    <div class="form-group">
        <label for="value">Decay Limit<br>
            <small class="form-text text-muted">
                The amount of solves before the challenge reaches its minimum value
            </small>
        </label>
        <input type="number" class="form-control chal-decay" name="decay" value="{{ challenge.decay }}" required>
    </div>

    <div class="form-group">
        <label for="value">Minimum Value<br>
            <small class="form-text text-muted">
                This is the lowest that the challenge can be worth
            </small>
        </label>
        <input type="number" class="form-control chal-minimum" name="minimum" value="{{ challenge.minimum }}" required>
    </div>

    <div class="form-group">
        <label>
            Max attempt<br>
            <small class="form-text text-muted">Maximum amount of attempts users receive. Leave at 0 for
                unlimited.</small>
        </label>

        <input type="number" class="form-control chal-attempts" name="max_attempts"
               value="{{ challenge.max_attempts }}">
    </div>

    <div class="form-group">
        <label for="value">Score Type<br>
            <small class="form-text text-muted">
                Decide it use dynamic score or not
            </small>
        </label>

        <select class="form-control" name="dynamic_score">
            <option value="0" {% if challenge.dynamic_score == 0 %}selected{% endif %}>Static Score</option>
            <option value="1" {% if challenge.dynamic_score == 1 %}selected{% endif %}>Dynamic Score</option>
        </select>
    </div>

    <div class="form-group">
        <label>
            State<br>
            <small class="form-text text-muted">Changes the state of the challenge (e.g. visible, hidden)</small>
        </label>

        <select class="form-control" name="state">
            <option value="visible" {% if challenge.state == "visible" %}selected{% endif %}>Visible</option>
            <option value="hidden" {% if challenge.state == "hidden" %}selected{% endif %}>Hidden</option>
        </select>
    </div>

    <div>
        <button class="btn btn-success btn-outlined float-right" type="submit">
            Update
        </button>
    </div>
</form>
